package gui.views.painter;

import model.environment.Obstacle;

import java.awt.*;
import java.util.ArrayList;


public class ObstaclePainter extends SimulWindowPainter {

	public static Color STANDARD_FOREGROUND_COLOR = Color.ORANGE;
	public static Color STANDARD_BACKGROUND_COLOR = Color.BLUE;

	public static Color STANDARD_OPAQUE_BACKGROUND_COLOR = Color.MAGENTA;
	public static Color STANDARD_OPAQUE_FOREGROUND_COLOR = Color.DARK_GRAY;

	private Color foregroundColor;
	private Color backgroundColor;

	private Color opaqueBackgroundColor;
	private Color opaqueForegroundColor;

	public ObstaclePainter() {
		this.foregroundColor = ObstaclePainter.STANDARD_FOREGROUND_COLOR;
		this.backgroundColor = ObstaclePainter.STANDARD_BACKGROUND_COLOR;

		this.opaqueBackgroundColor = ObstaclePainter.STANDARD_OPAQUE_BACKGROUND_COLOR;
		this.opaqueForegroundColor = ObstaclePainter.STANDARD_OPAQUE_FOREGROUND_COLOR;
	}

	@Override
	public void paint(Graphics g, ArrayList<Obstacle> obstacles) {
		for (Obstacle obstacle : obstacles) {
			paintObstacle(g, obstacle);
		}
	}

	public ObstaclePainter(Color foregroundColor, Color backgroundColor, Color opaqueBackgroundColor, Color opaqueForegroundColor) {
		this.foregroundColor = foregroundColor;
		this.backgroundColor = backgroundColor;

		this.opaqueBackgroundColor = opaqueBackgroundColor;
		this.opaqueForegroundColor = opaqueForegroundColor;
	}

	private void paintObstacle(Graphics g, Obstacle obstacle) {
		Polygon polygon = obstacle.getPolygon();
		boolean opaque = obstacle.getOpaque();

		if (opaque) {
			g.setColor(opaqueBackgroundColor);
			g.fillPolygon(polygon);
			g.setColor(opaqueForegroundColor);
			g.drawPolygon(polygon);
		} else {
			g.setColor(backgroundColor);
			g.fillPolygon(polygon);
			g.setColor(foregroundColor);
			g.drawPolygon(polygon);
		}

	}
}
